﻿//http://www.51aspx.com/CodeFile/GYCMSWeb,7636/Manager/lib/ligerUI/js/plugins/ligerTree.js.html
var manager = null;
var url = "../Permission/TreeDate?rand="+Math.random();
$(function () {
    InitOrgData();
    $("#btnCommit").unbind("click").bind("click", getSelectTreeNode);
});
 function InitOrgData() {
     $.get(url, { "roleId": $("#hidRoleId").val(),"typeName":$("#HidTypeName").val() }, function (orgdata) {
         if (orgdata != undefined) {
             if (manager != null && manager != undefined) { manager.clear(); }
             manager = $(".l-tree").ligerTree({
                 data: [orgdata],
                 isExpand: 2,
                 checkbox: true,
                 slide: false
             });
             $("#initLoadingImg").css("display", "none");

         }
     });
 }

 //获取选中的树结点(可多选 角色权限用)
 function getSelectTreeNode() {
     var orgArray ="";
     var uiArray ="";
     if (manager != null&&manager!=undefined) {
         var nodes = manager.getChecked();
         if (nodes != undefined && nodes != null) {
             for (var i = 0; i < nodes.length; i++) {
                 if (nodes[i].data.isorg.toString()=="1") {
                     orgArray += nodes[i].data.id + "@";
                 }
                 else {
                     uiArray += nodes[i].data.id + "@";
                 }
             }
         }
     }
     // return resultArray;
     $.post("../Role/SetRolePermissions", { "roleid": $("#hidRoleId").val(), "orgpermissions": orgArray.toString(), "uipermissions": uiArray.toString(), "typeName": $("#HidTypeName").val() }, function (data) {
         if (data != undefined && data == "ok") {
             ajaxSubmitSuccess();
             $.ligerDialog.success('操作成功!');
         }
         else {
             $.ligerDialog.success('操作失败！');
         }
     });
}

//点击
function clickGetData(tn,index) {
    $("#HidTypeName").val(tn);
    $("#treeNodesData>ul").html("");
    $("#leftTypeList>li").removeClass("selected");
    $("#leftTypeList>li").eq(index).addClass("selected");
    $("#initLoadingImg").css("display", "");
   // f_selectNode(tn);
    InitOrgData();
}

function f_selectNode(typename) {
    $("#treeNodesData li").css({ "display": "" });
    var parm = function (data) {

        if (typename != '全部') {
            if (data.typename != null && data.typename != undefined && data.typename.substring(1) != typename) {
                //data.css({"display":"none"});
                $("#treeNodesData li #" + data.id).css({ "display": "none" });
            }
        }
        else {
            $("#treeNodesData li #" + data.id).css({ "display": "" });
        }
        // return data.typename.substring(1).indexOf(typename) == 0;
        // alert(data.typename);
    };

   // manager.selectNode(parm);
}
